﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;

namespace KNXObjects
{
    public class TimeObject : GenericObjectBase<DateTime>
    {
        #region ObjectBase Implementations

        public override string DataPointEISName
        {
            get { return "EIS3"; }
        }

        public override string DataPointID
        {
            get { return "10.001"; }
        }

        public override string ToString()
        {
            return Value.ToString("hh:mm:ss");
        }

        public override void SetValue(string value)
        {
            if (value.ToLower() == "now")
                Value = DateTime.Now;
            else
            {
                DateTime val;
                if (!DateTime.TryParseExact(value, "H:mm:ss", CultureInfo.CurrentCulture, DateTimeStyles.NoCurrentDateDefault, out val))
                    throw new ApplicationException("TimeObject cannot parse value as datetime. Val : " + value);

                Value = val;

            }
        }

        #endregion

        #region ctor

        public TimeObject(string id, string address, string name, string flags)
            : base(id, address, name, flags)
        {
        }

        public TimeObject(string value)
        {
            SetValue(value);
        }
        #endregion
    }
}
